<?php

class ControlPanel {

	var $default_settings = Array(
	'featured_n' => '10',
	'leftcatsN' => '4',
	'rightcatsN' => '4',
	'viewed_num' => '10',
	'recent_num' => '10',
	'discussed_num' => '10',
	'style' => 'default',
	'language' => 'english.php',
	'loptions' => 1,
	'adblock1_show' => 1,
	'adblock2_show' => 1,
	'date' => 1,
	'logo' => 1,
	'pagenav' => 1,
	'videose' => 1,
	'subscribe' => 1,
	'author' => 1,
	'widgets' => 1,
	'widgetsl' => 1,
	'widgetsr' => 1,
	'menu' => 1,
	'search' => 1,
	'ajaxtabs' => 1,
	'ctabs' => 1,
	'featuredarea' => 1,
	'fc' => 1,
	'footernav' => 1,
	'postinfo' => 1,
	'adm' => 1,
	'tree' => 1,
	'crop' => 1,
	'quality' => '95',
	'FTwidth' => '180',
	'FTheight' => '130',
	'MTwidth' => '100',
	'MTheight' => '70',
	'GTwidth' => '100',
	'GTheight' => '70',
	);
	
	var $options;

	function ControlPanel() {
    add_action('admin_menu', array(&$this, 'add_menu'));
	add_action('admin_head', array(&$this, 'admin_head'));
	if (!is_array(get_option('comfy')))
	add_option('comfy', $this->default_settings);
	$this->options = get_option('comfy');
	}

	function add_menu() {
	add_theme_page('主题控制面板', '主题控制面板', 8, "comfy", array(&$this, 'optionsmenu'));
	}
	
	function admin_head() {
	print '<link rel="stylesheet" href="'.get_template_directory_uri().'/cp/css/style.css" type="text/css" media="screen" />';
	print '<script type="text/javascript" src="'.get_template_directory_uri().'/cp/js/tabs.js"></script>';
	}

	/********************************************************
	options page
	********************************************************/
	function optionsmenu() {
	
	// PROCESSING
	if ($_POST['cp_reset'] == 'Restore Defaults') {
	delete_option('comfy', $this->options);
	echo '<div class="updated fade msg" id="message"><p>Your settings have been reset to defaults.</p></div>';
	} elseif ($_POST['ss_action'] == 'save') {
	$this->options["featured"] = $_POST['cp_featured'];
	$this->options["featured_n"] = $_POST['cp_featured_n'];
	$this->options["feed_name"] = $_POST['cp_feed_name'];
	$this->options["leftcatsN"] = $_POST['cp_leftcatsN'];
	$this->options["recent_num"] = $_POST['cp_recent_num'];
	$this->options["viewed_num"] = $_POST['cp_viewed_num'];
	$this->options["discussed_num"] = $_POST['cp_discussed_num'];
	$this->options["videos"] = $_POST['cp_videos'];
	$this->options["videose"] = $_POST['cp_videose'];
	$this->options["adblock1"] = stripslashes($_POST['cp_adblock1']);
	$this->options["adblock2"] = stripslashes($_POST['cp_adblock2']);
	$this->options["loptions"] = $_POST['cp_loptions'];
	$this->options["adblock1_show"] = $_POST['cp_adblock1_show'];
	$this->options["adblock2_show"] = $_POST['cp_adblock2_show'];
	$this->options["date"] = $_POST['cp_date'];
	$this->options["logo"] = $_POST['cp_logo'];
	$this->options["pagenav"] = $_POST['cp_pagenav'];
	$this->options["style"] = $_POST['cp_style'];
	$this->options["language"] = $_POST['cp_language'];
	$this->options["subscribe"] = $_POST['cp_subscribe'];
	$this->options["author"] = $_POST['cp_author'];
	$this->options["widgets"] = $_POST['cp_widgets'];
	$this->options["widgetsl"] = $_POST['cp_widgetsl'];
	$this->options["widgetsr"] = $_POST['cp_widgetsr'];
	$this->options["menu"] = $_POST['cp_menu'];
	$this->options["search"] = $_POST['cp_search'];
	$this->options["ajaxtabs"] = $_POST['cp_ajaxtabs'];
	$this->options["ctabs"] = $_POST['cp_ctabs'];
	$this->options["featuredarea"] = $_POST['cp_featuredarea'];
	$this->options["fc"] = $_POST['cp_fc'];
	$this->options["footernav"] = $_POST['cp_footernav'];
	$this->options["adm"] = $_POST['cp_adm'];
	$this->options["postinfo"] = $_POST['cp_postinfo'];
	$this->options["tree"] = $_POST['cp_tree'];
	$this->options["crop"] = $_POST['cp_crop'];
	$this->options["quality"] = $_POST['cp_quality'];
	$this->options["FTwidth"] = $_POST['cp_FTwidth'];
	$this->options["FTheight"] = $_POST['cp_FTheight'];
	$this->options["MTwidth"] = $_POST['cp_MTwidth'];
	$this->options["MTheight"] = $_POST['cp_MTheight'];
	$this->options["GTwidth"] = $_POST['cp_GTwidth'];
	$this->options["GTheight"] = $_POST['cp_GTheight'];
	$this->options["leftcatsN"] = $_POST['cp_leftcatsN'];
	$this->options["rightcatsN"] = $_POST['cp_rightcatsN'];
	for ($i = 1; $i <= $_POST['cp_leftcatsN']; $i++) {
	$this->options["leftcats".$i] = $_POST['cp_leftcats'.$i];
	}
	for ($i = 1; $i <= $_POST['cp_rightcatsN']; $i++) {
	$this->options["rightcats".$i] = $_POST['cp_rightcats'.$i];
	}
	update_option('comfy', $this->options);
	echo '<div class="updated fade msg" id="message"><p>Your changes have been saved.</p></div>';
	}
	
	// Remove Extension
	function remove_ext($filename) {
		$file = substr($filename, 0,strrpos($filename,'.'));
		return $file;
	}
	
	?>
	
	<?php
	print '<script type="text/javascript" src="'.get_template_directory_uri().'/cp/js/jquery-1.3.1.min.js"></script>';
	print '<script type="text/javascript" src="'.get_template_directory_uri().'/cp/js/jquery.textarearesizer.js"></script>';
	print '<script type="text/javascript">
			$(document).ready(function() {
			$("textarea.resizable:not(.processed)").TextAreaResizer();
			});
			</script>';
	?>
	
	<form action="" method="post" class="themeform">
	<input type="hidden" id="ss_action" name="ss_action" value="save">
	
	<ul class="cpdesign">
	<li style="width:18%">
	<div class="title">Control Panel <span class="powered">Powered by Deluxe Themes</span></div>
	<ul id="cptabs" class="cptabs">
	<li><a href="#" rel="1" class="selected">Featured Entries</a></li>
	<li><a href="#" rel="3">Featured Categories</a></li>
	<li><a href="#" rel="11">Thumbnail Manager</a></li>
	<li><a href="#" rel="4">Ajax Tabs</a></li>
	<li><a href="#" rel="6">Video Manager</a></li>
	<li><a href="#" rel="2">FeedBurner</a></li>
	<li><a href="#" rel="5">Ad Manager</a></li>
	<li><a href="#" rel="9">Style Manager</a></li>
	<li><a href="#" rel="12">Language Manager</a></li>
	<li><a href="#" rel="8">Module Manager</a></li>
	<li><a href="#" rel="7">Update Checker</a></li>
	<li><a href="#" rel="10">Theme Doctor</a></li>
	</ul><div class="clear"></div>
	</li>
	<li style="width:82%">
	<?php include_once TEMPLATEPATH. '/cp/submodules/panel.thumbnails.php'; ?>
	<?php include_once TEMPLATEPATH. '/cp/submodules/panel.features.php'; ?>
	<?php include_once TEMPLATEPATH. '/cp/submodules/panel.feedburner.php'; ?>
	<?php include_once TEMPLATEPATH. '/cp/submodules/panel.featuredcategories.php'; ?>
	<?php include_once TEMPLATEPATH. '/cp/submodules/panel.ajaxtabs.php'; ?>
	<?php include_once TEMPLATEPATH. '/cp/submodules/panel.videos.php'; ?>
	<?php include_once TEMPLATEPATH. '/cp/submodules/panel.admanager.php'; ?>
	<?php include_once TEMPLATEPATH. '/cp/submodules/panel.updater.php'; ?>
	<?php include_once TEMPLATEPATH. '/cp/submodules/panel.modules.php'; ?>
	<?php include_once TEMPLATEPATH. '/cp/submodules/panel.styles.php'; ?>
	<?php include_once TEMPLATEPATH. '/cp/submodules/panel.languages.php'; ?>
	<?php include_once TEMPLATEPATH. '/cp/submodules/panel.doctor.php'; ?>
	<input type="submit" value="Save Changes" name="cp_save" class="button-primary" />
	<input type="submit" value="Restore Defaults" name="cp_reset" class="button" />
	</li>
	</ul><div class="clear"></div>

	<script type="text/javascript">
	var cptabs=new ddtabcontent("cptabs")
	cptabs.setpersist(true)
	cptabs.setselectedClassTarget("link")
	cptabs.init()
	</script>

	</form>
	
	<?php
	
	} // options page

} // control panel

// start control panel
$cpanel = new ControlPanel();
$comfy = get_option('comfy');

?>